import { DataTypes } from 'sequelize';
import sequelize from '../config/db.config.js';

const Person = sequelize.define('Person', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true,
    field: 'person_id'
  },
  familyTreeId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'family_trees',
      key: 'family_tree_id'
    },
    field: 'family_tree_id'
  },
  name: {
    type: DataTypes.STRING(100),
    allowNull: false
  },
  gender: {
    type: DataTypes.STRING(10),
    allowNull: false,
    validate: {
      isIn: [['男', '女']]
    }
  },
  birthDate: {
    type: DataTypes.DATEONLY,
    allowNull: true
  },
  generation: {
    type: DataTypes.INTEGER,
    allowNull: true,
    comment: '世代信息，第几代'
  },
  deathDate: {
    type: DataTypes.DATEONLY,
    allowNull: true
  },
  occupation: {
    type: DataTypes.STRING(100),
    allowNull: true
  },
  education: {
    type: DataTypes.STRING(50),
    allowNull: true
  },
  address: {
    type: DataTypes.STRING(200),
    allowNull: true
  },
  maritalStatus: {
    type: DataTypes.STRING(20),
    allowNull: true,
    validate: {
      isIn: [['未婚', '已婚', '离异', '丧偶']]
    }
  },
  phone: {
    type: DataTypes.STRING(20),
    allowNull: true
  },
  email: {
    type: DataTypes.STRING(100),
    allowNull: true
  },
  description: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  photos: {
    type: DataTypes.JSON,
    allowNull: true,
    defaultValue: []
  },
  avatar: {
    type: DataTypes.STRING,
    allowNull: true
  }
}, {
  tableName: 'persons',
  timestamps: true,
  paranoid: true,
  deletedAt: 'deleted_at'
});

export default Person; 